//
//  SleepView.m
//  JunZeWristband
//
//  Created by Kendama on 2017/9/9.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "SleepView.h"

@implementation SleepView

- (UIImageView *)bgImageView
{
    if(!_bgImageView)
    {
        UIView *superView = self;
        _bgImageView = [[UIImageView alloc]init];
        [superView addSubview:_bgImageView];
        _bgImageView.image = [UIImage imageNamed:@"bg_red"];
    }
    return _bgImageView;
}
- (UIImageView *)circleBgView
{
    if(!_circleBgView)
    {
        UIView *superView = self;
        _circleBgView = [[UIImageView alloc]init];
        [superView addSubview:_circleBgView];
        _circleBgView.image = [UIImage imageNamed:@"bg_sleep"];
    }
    return _circleBgView;
}
- (UIImageView *)circleView
{
    if(!_circleView)
    {
        UIView *superView = self;
        _circleView = [[UIImageView alloc]init];
        [superView addSubview:_circleView];
        _circleView.image = [UIImage imageNamed:@"gif_pink"];
    }
    return _circleView;
}

- (UILabel *)stepLabel
{
    if(!_stepLabel)
    {
        UIView *superView = self;
        _stepLabel = [[UILabel alloc]init];
        [superView addSubview:_stepLabel];
        [_stepLabel setFont:[UIFont systemFontOfSize:40]];
        [_stepLabel setTextColor:[UIColor colorWithHexString:@"FD9D9D"]];
        _stepLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _stepLabel;
}

- (UILabel *)titleLabel
{
    if(!_titleLabel)
    {
        UIView *superView = self;
        _titleLabel = [[UILabel alloc]init];
        [superView addSubview:_titleLabel];
        [_titleLabel setFont:[UIFont systemFontOfSize:15]];
        [_titleLabel setTextColor:[UIColor darkGrayColor]];
    }
    return _titleLabel;
}

- (UILabel *)unitLabel
{
    if(!_unitLabel)
    {
        UIView *superView = self;
        _unitLabel = [[UILabel alloc]init];
        [superView addSubview:_unitLabel];
        [_unitLabel setFont:[UIFont systemFontOfSize:15]];
        [_unitLabel setTextColor:[UIColor colorWithHexString:@"FD9D9D"]];
    }
    return _unitLabel;
}

- (DataView *)dateView
{
    if(!_dateView)
    {
        UIView *superView = self;
        _dateView = [[DataView alloc]init];
        [superView addSubview:_dateView];
        _dateView.dataLabel.textColor = [UIColor colorWithHexString:@"FD9D9D"];
    }
    return _dateView;
}
- (DataView *)distanceView
{
    if(!_distanceView)
    {
        UIView *superView = self;
        _distanceView = [[DataView alloc]init];
        [superView addSubview:_distanceView];
        _distanceView.dataLabel.textColor = [UIColor colorWithHexString:@"FD9D9D"];
        
    }
    return _distanceView;
}
- (DataView *)targetView
{
    if(!_targetView)
    {
        UIView *superView = self;
        _targetView = [[DataView alloc]init];
        [superView addSubview:_targetView];
        _targetView.dataLabel.textColor = [UIColor colorWithHexString:@"FD9D9D"];
        
    }
    return _targetView;
}
- (UIButton *)dateButton
{
    if(!_dateButton)
    {
        UIView *superView = self;
        _dateButton = [[UIButton alloc]init];
        [superView addSubview:_dateButton];
        [_dateButton setImage:[UIImage imageNamed:@"icon_date"] forState:UIControlStateNormal];
    }
    return _dateButton;
}
- (UIButton *)leftButton
{
    if(!_leftButton)
    {
        UIView *superView = self;
        _leftButton = [[UIButton alloc]init];
        [superView addSubview:_leftButton];
        [_leftButton setImage:[UIImage imageNamed:@"but_left_pink"] forState:UIControlStateNormal];
    }
    return _leftButton;
}
- (UIButton *)rightButton
{
    if(!_rightButton)
    {
        UIView *superView = self;
        _rightButton = [[UIButton alloc]init];
        [superView addSubview:_rightButton];
        [_rightButton setImage:[UIImage imageNamed:@"but_right_pink"] forState:UIControlStateNormal];
    }
    return _rightButton;
}



- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top);
        make.left.right.mas_equalTo(superView);
        make.height.mas_equalTo(px1920Height(1030));
    }];
    
    [self.circleBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(100));
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.height.width.mas_equalTo(px1920Height(800));
    }];
    
    [self.circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.circleBgView);
        make.height.width.mas_equalTo(px1920Height(500));
    }];
    
    [self.stepLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.circleView);
        
    }];
    
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.stepLabel.mas_bottom).with.offset(px1080Width(-40));
        make.left.mas_equalTo(self.stepLabel.mas_right).with.offset(px1080Width(20));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.stepLabel);
        make.top.mas_equalTo(self.stepLabel.mas_bottom).with.offset(px1920Height(20));
    }];
    
    [self.dateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(49));
        make.right.mas_equalTo(superView.mas_right).with.offset(px1080Width(-49));
    }];
    
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.circleBgView.mas_centerY);
        make.left.mas_equalTo(superView.mas_left);
    }];
    
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.circleBgView.mas_centerY);
        make.right.mas_equalTo(superView.mas_right);
    }];
    
    CGFloat padding = px1080Width(50);
    NSMutableArray *views = [NSMutableArray array];
    [views addObjectsFromArray:@[self.dateView,self.distanceView,self.targetView]];
    [views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:px1080Width(280) leadSpacing:padding tailSpacing:padding];
    [views mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(superView.mas_bottom).with.offset(px1920Height(-300));
        UIView *blueView = (UIView *)views[0];
        make.height.mas_equalTo(blueView.mas_width);
    }];
    
    self.stepLabel.text = @"0.0";
    self.titleLabel.text = MyNSLocalizedString(@"今日睡眠");
    self.dateView.dataLabel.text = @"0.0";
    self.dateView.unitLabel.text = MyNSLocalizedString(@"深睡眠（小时）");
    self.distanceView.dataLabel.text = @"0.0";
    self.distanceView.unitLabel.text = MyNSLocalizedString(@"浅睡眠（小时）");
    self.targetView.dataLabel.text = @"8.8";
    self.targetView.unitLabel.text = MyNSLocalizedString(@"目标（小时）");
    self.unitLabel.text = MyNSLocalizedString(@"小时");
}


@end
